package com.bbm.bbmanage.exception;

import com.bbm.bbmanage.entity.AppHttpCodeEnum;
import com.bbm.bbmanage.entity.vo.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @description: 自定义异常处理
 */
@Slf4j
@ControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResponseResult exceptionHandler(Exception e) {
        log.error("全局异常捕获>>>: {}", e);
        ResponseResult<Object> responseResult = new ResponseResult<>();
        responseResult.setCode(AppHttpCodeEnum.SYSTEM_ERROR.getCode())
                .setMessage(e.getMessage());
        return responseResult;
    }
}
